package com.situ.web.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.situ.web.dao.IBanjiDao;
import com.situ.web.entity.Banji;
import com.situ.web.entity.Course;
import com.situ.web.util.JDBCUtil;

public class BanjiDaoImpl implements IBanjiDao {

	@Override
	public List<Banji> selectAll() {
		Connection connection = null;
		PreparedStatement statement = null;
		ResultSet resultSet = null;
		List<Banji> list = new ArrayList<Banji>();
		try {
			connection = JDBCUtil.getConnection();
			String sql = "SELECT `id`,`name` FROM `banji`";
			statement = connection.prepareStatement(sql);
			resultSet = statement.executeQuery();
			System.out.println(statement);
			while (resultSet.next()) {
				int id = resultSet.getInt("id");
				String name = resultSet.getString("name");
				Banji banji = new Banji(id, name);
				list.add(banji);
			}
			for (Banji banji : list) {
				System.out.println(banji);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBCUtil.close(connection, statement, resultSet);
		}
		
		return list;
	}

}
